package com.study.myteach.发布订阅模式;

import java.util.LinkedList;
import java.util.List;

/**
 * @author lk
 * @date 2021/4/30 0030 11:29
 * @description:
 */
public class WeatherStation {
    private Weather weather;
    private static List<Observer> observers = new LinkedList<>();


    public static void stateChange(Weather weather) {
        for (Observer observer : observers) {
            observer.update(weather);
        }
    }

    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    public void deleteObserver(Observer observer) {
        observers.remove(observer);
    }


    public Weather getWeather() {
        return weather;
    }

    public void setWeather(Weather weather) {
        this.weather = weather;
        this.stateChange(weather);
    }
}
